package com.me.service;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.me.dao.ConfigDAO;
import com.me.entity.Config;

@Service
public class ConfigService extends BaseService<Config, ConfigDAO> {
	/**
	 * 注入持久层对象
	 */
	@Resource
	private ConfigDAO configDAO;

	@Override
	protected ConfigDAO getDao() {
		return configDAO;
	}
	
	/**
	 * 获取考试总时间(分钟数)
	 */
	public String getTotalTime(){
		Integer index = 100;
		Config config = configDAO.queryByPropIndex(index);
		return config.getPropValue();
	}
	
	/**
	 * 获取考试截止时间，格式：yyyy/MM/dd HH:mm:ss
	 */
	public String getEndTime(long startTime){
		String min = getTotalTime();
		int millionSec = Integer.parseInt(min) * 60 * 1000;
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
		long endTime = startTime + millionSec;
		return sdf.format(new Date(endTime));
	}
	
	/**
	 * 获取选择题的数量
	 */
	public Integer getChoiceNum(){
		Integer index = 101;
		Config config = configDAO.queryByPropIndex(index);
		return Integer.parseInt(config.getPropValue());
	}
	
	/**
	 * 获取问答题的数量
	 */
	public Integer getQuestionNum(){
		Integer index = 102;
		Config config = configDAO.queryByPropIndex(index);
		return Integer.parseInt(config.getPropValue());
	}
	
	/**
	 * 获取每道选择题的分数
	 */
	public Integer getChoiceScore(){
		Integer index = 104;
		Config config = configDAO.queryByPropIndex(index);
		return Integer.parseInt(config.getPropValue());
	}
	
	/**
	 * 获取默认的平时成绩
	 */
	public Integer getRegularScore(){
		Integer index = 105;
		Config config = configDAO.queryByPropIndex(index);
		return Integer.parseInt(config.getPropValue());
	}
}
